package cn.dankal.flyaudio.personal.setting;

import android.content.Intent;
import android.graphics.Color;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import butterknife.BindView;
import butterknife.OnClick;
import cn.dankal.basiclib.DKUserManager;
import cn.dankal.basiclib.base.activity.BaseActivity;
import cn.dankal.basiclib.protocol.PersonalProtocol;
import cn.dankal.basiclib.util.ActivityUtils;
import cn.dankal.basiclib.util.CallPhoneUtil;
import cn.dankal.basiclib.widget.CommonDialog;
import cn.dankal.basiclib.widget.titlebar.SingleTextTitle;
import cn.dankal.flyaudio.R;

/**
 * description: 设置界面
 *
 * @author vane
 * @since 2018/8/7
 */
@Route(path = PersonalProtocol.SETTING)
public class SettingActivity extends BaseActivity {


    //是否强制更新
    private boolean force;


    @BindView(R.id.tv_phone_num)
    TextView tv_phone_num;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initComponents() {
        addTitleBar(new SingleTextTitle("设置"));
    }

    @OnClick(R.id.fl_contact)
    public void onFlContact() {
        CallPhoneUtil.callPhoneAndPermission(this,tv_phone_num.getText().toString());
    }

    @OnClick(R.id.fl_about_me)
    public void onFlAboutMeClicked() {
        ARouter.getInstance().build(PersonalProtocol.ABOUT_US).navigation();
    }

    @OnClick(R.id.fl_feedback)
    public void onFlFeedbackClicked() {
        ARouter.getInstance().build(PersonalProtocol.FEEDBACK).navigation();
    }


    @OnClick(R.id.fl_check)
    public void onFlCheckVersionClicked() {
        ARouter.getInstance().build(PersonalProtocol.APP_VERSION).navigation();
    }



    @OnClick(R.id.bt_logout)
    public void onFlLogoutClicked() {
        CommonDialog.Builder builder = new CommonDialog.Builder(this);
        builder.setTitle("是否确定退出登录？")
                .setPositiveButton("确定", Color.parseColor("#141414"), type -> {
                    DKUserManager.resetToken();
                    DKUserManager.resetUserInfo();
                    ActivityUtils.finishAllActivities();
                    try {
                        startActivity(new Intent(this,
                                Class.forName(getString(cn.dankal.basiclib.R.string.login_activity_path))));
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    //builder.getDialog().dismiss();
                })
                .setNegativeButton("取消", Color.parseColor("#141414"), type -> builder.getDialog().dismiss())
                .create()
                .show();
    }

}
